package top.drinyeit.nongmao.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;

import java.util.List;

import top.drinyeit.nongmao.R;
import top.drinyeit.nongmao.model.ClassificationBean;
import top.drinyeit.nongmao.view.CarouselView;

/**
 * Created by wu on 2018/1/11.
 */

public class ClassificationCVAdapter implements CarouselView.Adapter {
    private List<ClassificationBean.BannerBean> list;
    private Context context;

    public ClassificationCVAdapter(Context context, List<ClassificationBean.BannerBean> list){
        this.context = context;
        this.list = list;
    }
    @Override
    public boolean isEmpty() {
        return false;
    }

    @Override
    public View getView(int position) {
        View view = View.inflate(context, R.layout.item, null);
        ImageView imageView = view.findViewById(R.id.image);
        Glide.with(context)
                .load(list.get(position).getBanner_img_url())
                .dontTransform()
                .placeholder(R.drawable.ic_def)
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .into(imageView);
        return view;
    }

    @Override
    public void clear() {
        this.list.clear();
    }

    public void setData(List<ClassificationBean.BannerBean> list){
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null? 0 : list.size();
    }
}
